﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a section of text using a different font.
    /// </summary>
    [Serializable]
    [Obsolete("Deprecated in HTML4 - use CSS instead.")]
    public class Font : Element {
        private Color? _color;
        private IList<string> _face;
        private int? _size;

        /// <summary>
        /// Creates a new instance of a Font tag.
        /// </summary>
        public Font() {
            _face = new List<string>();
        }

        /// <summary>
        /// Determines the color of the font.
        /// </summary>
        public Color? Color {
            get { return _color; }
            set { _color = value; }
        }

        /// <summary>
        /// Gets a list of the font faces, with the first taking the most
        /// priority when rendered.
        /// </summary>
        public IList<string> Face {
            get { return _face; }
        }

        /// <summary>
        /// Determines the size of the font.
        /// </summary>
        public int? Size {
            get { return _size; }
            set {
                if (value == null || (value > 0 && value < 8)) {
                    _size = value;
                } else {
                    throw new ArgumentException(
                        "The argument must be between 1 and 7, inclusive.",
                        "value");
                }
            }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _color, "color");
            AttributeWriter.Write(sb, _face, "face", ',');
            AttributeWriter.Write(sb, _size, "size");
        }
    }
}
